import Vue from "vue";
import Router from "vue-router";
import Index from "@views/mobile/Index";
import WebIndex from "@views/pc/Index";
import NotDefined from "@views/NotDefined";
import $store from "../store";
import Loading from "@views/Loading";

Vue.use(Router);

const router = new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      name: "Index",
      meta: {
        title: "首页",
        keepAlive: true,
        footer: true,
        backgroundColor: "#fff"
      },
      component: Index
    },
    {
      path: "/web/index",
      name: "Index",
      meta: {
        title: "首页",
        keepAlive: true,
        footer: true,
        backgroundColor: "#fff"
      },
      component: WebIndex
    },
    {
      path: "/main",
      name: "Main",
      meta: {
        title: "主页",
        keepAlive: true,
        footer: true,
        backgroundColor: "#fff"
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Main.vue")
    },
    {
      path: "/web/main",
      name: "Main",
      meta: {
        title: "主页",
        keepAlive: true,
        footer: true,
        backgroundColor: "#fff"
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Main.vue")
    },
    {
      path: "/login",
      name: "Login",
      meta: {
        title: "登录",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Login.vue")
    },
    {
      path: "/web/login",
      name: "Login",
      meta: {
        title: "登录",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Login.vue")
    },
    {
      path: "/gold",
      name: "Gold",
      meta: {
        title: "金币商城",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Gold.vue")
    },
    {
      path: "/web/gold",
      name: "Gold",
      meta: {
        title: "金币商城",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Gold.vue")
    },
    {
      path: "/rank",
      name: "Rank",
      meta: {
        title: "排行榜",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Rank.vue")
    },
    {
      path: "/web/rank",
      name: "Rank",
      meta: {
        title: "排行榜",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Rank.vue")
    },
    {
      path: "/buy",
      name: "Buy",
      meta: {
        title: "购买课程",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Buy.vue")
    },
    {
      path: "/web/buy",
      name: "Buy",
      meta: {
        title: "购买课程",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Buy.vue")
    },

    {
      path: "/draw",
      name: "Draw",
      meta: {
        title: "抽奖",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Draw.vue")
    },
    {
      path: "/web/draw",
      name: "Draw",
      meta: {
        title: "抽奖",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Draw.vue")
    },
    {
      path: "/get",
      name: "Get",
      meta: {
        title: "开始学习赚金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Get.vue")
    },
    {
      path: "/web/get",
      name: "Get",
      meta: {
        title: "开始学习赚金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Get.vue")
    },
    {
      path: "/learn",
      name: "Learn",
      meta: {
        title: "学习赚金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Learn.vue")
    },
    {
      path: "/web/learn",
      name: "Learn",
      meta: {
        title: "学习赚金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Learn.vue")
    },
    {
      path: "/log",
      name: "Log",
      meta: {
        title: "学习记录",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Log.vue")
    },
    {
      path: "/web/log",
      name: "Log",
      meta: {
        title: "学习记录",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Log.vue")
    },

    {
      path: "/user",
      name: "User",
      meta: {
        title: "个人中心",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/User.vue")
    },
    {
      path: "/web/user",
      name: "User",
      meta: {
        title: "个人中心",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/User.vue")
    },
    {
      path: "/my",
      name: "My",
      meta: {
        title: "个人中心",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/My.vue")
    },
    {
      path: "/web/my",
      name: "My",
      meta: {
        title: "个人中心",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/My.vue")
    },
    {
      path: "/recom",
      name: "recom",
      meta: {
        title: "听音识图",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Recom.vue")
    },
    {
      path: "/web/Recom",
      name: "Recom",
      meta: {
        title: "听音识图",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/Recom.vue")
    },
    {
      path: "/goldcoin",
      name: "GoldCoin",
      meta: {
        title: "学习领取金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/GoldCoin.vue")
    },
    {
      path: "/web/goldcoin",
      name: "GoldCoin",
      meta: {
        title: "学习领取金币",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/pc/GoldCoin.vue")
    },
    {
      path: "/test",
      name: "Test",
      meta: {
        title: "测试",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "@views/mobile/Test.vue")
    },
    {
      path: "/auth/:url",
      name: "Loading",
      meta: {
        title: " 加载中",
        keepAlive: true
      },
      component: Loading
    },
    {
      path: "*",
      name: "NotDefined",
      meta: {
        title: "页面找不到",
        keepAlive: true,
        home: false,
        backgroundColor: "#F4F6FB"
      },
      component: NotDefined
    },
    {
      path: '/_Login'
      ,name: '_Login'
      ,meta: {
        title: '登录'
        ,keepAlive: true
      }
      ,component: ()=> import('@views/mobile/_Login.vue')
    }
  ],
  scrollBehavior(to, from) {
    from.meta.scrollTop = window.scrollY;
    return { x: 0, y: to.meta.scrollTop || 0 };
  }
});

const { back, replace } = router;

router.back = function() {
  this.isBack = true;
  back.call(router);
};
router.replace = function(...args) {
  this.isReplace = true;
  replace.call(router, ...args);
};

// router.beforeEach((to, form, next) => {
//   const { title, backgroundColor, footer, home, auth } = to.meta;
//   document.title = title || process.env.VUE_APP_NAME || "点点教育";
//   //判断是否显示底部导航
//   footer === true ? $store.commit("SHOW_FOOTER") : $store.commit("HIDE_FOOTER");
//
//   //控制悬浮按钮是否显示
//   home === false ? $store.commit("HIDE_HOME") : $store.commit("SHOW_HOME");
//
//   $store.commit("BACKGROUND_COLOR", backgroundColor || "#F5F5F5");
//
//   if (auth) {
//     $store.dispatch("USERINFO").then(() => {
//       next();
//     });
//   } else next();
// });

export default router;
